package com.yst.sqlbuilder;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Group of expression
 */
public interface IExpressionGroup extends IExpression {

    enum LinkMode implements IExpression{
        OR("OR"),
        AND("AND");

        public final String expression;
        LinkMode(String expression){
            this.expression=expression;
        }

        @Override
        public String generateExpression(GenerateParam param) {
            return expression;
        }
    }

    @Override
    default String generateExpression(GenerateParam param) {
        if (getExpressions().length>0) {
            return Arrays.stream(getExpressions()).map(it->it.generateExpression(param))
                    .collect(Collectors.joining(getLinkMode().expression, "(", ")"));
        }
        return "";
    }

    default LinkMode getLinkMode(){
        return LinkMode.AND;
    }

    default IExpression[] getExpressions(){
         return new IExpression[0];
    }

}
